package com.fenqing.leetcode.code.t700_800;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.Arrays;

/**
 * @author fenqing
 */
public class Topic733 extends Topic {
    /**
     * 构造器
     *
     * @param input1        输入
     * @param input2
     * @param input3
     * @param input4
     */
    public Topic733(String input1, String input2, String input3, String input4) {
        super(input1, input2, input3, input4);
    }

    @Execute
    public int[][] floodFill(int[][] image, int sr, int sc, int color) {
        int oldColor = image[sr][sc];
        int xLen = image.length, yLen = image[0].length;
        int[][] ints = new int[xLen][yLen];
        floodFill(image, oldColor, sr, sc, color, ints);
        return image;
    }

    public void floodFill(int[][] image, int oldColor, int x, int y, int color,  int[][] complete){

        int xLen = image.length, yLen = image[0].length;
        if (x >= 0 && x < xLen && y >= 0 && y < yLen && image[x][y] == oldColor){
            if (complete[x][y] == 1) {
                return;
            }
            complete[x][y] = 1;
            image[x][y] = color;
            floodFill(image, oldColor, x - 1, y, color, complete);
            floodFill(image, oldColor, x + 1, y, color, complete);
            floodFill(image, oldColor, x, y - 1, color, complete);
            floodFill(image, oldColor, x, y + 1, color, complete);
        }
    }

    public static void main(String[] args) {
        Topic733 topic733 = new Topic733("[[0,0,0],[0,0,0]]", "0", "0", "0");
        System.out.println(Arrays.deepToString(topic733.run()));
    }

}
